package bank;

import framework.account.AAccountObserver;
import framework.account.IAccount;
import framework.account.IEntry;
import framework.customer.ACustomer;
import framework.mvc.FincoContext;

public class BankAccountObserver extends AAccountObserver {

    public BankAccountObserver(IAccount account) {
        super(account);
    }

    @Override
    protected void successAction(IAccount account, IEntry iEntry) {
        //update UI: account balance
        FincoContext.getView().getViewModel().setValueAt(account.getBalance(), FincoContext.getView().getRowSelectedIndex(), 5);

        //TODO needs generalized messages
        if (account.getCustomer().getType().equals(ACustomer.Type.COMPANY))
            BankService.sendEmail(account);
        else {
            if (iEntry.getAmount() > 500 || account.getBalance() < 0) {
                BankService.sendEmail(account);
            }
        }
    }

    @Override
    protected void failAction(IAccount account, IEntry iEntry) {
        //TODO implement
    }
}